import { defineStore } from "pinia";

export const useMyTimeoutStore = defineStore({
  id: "myTimeoutStore",
  state: () => ({
    timeOutSec: 0,
    cb: undefined as undefined | AnyVoidFunction,
    nowTime: 0,
  }),
  getters: {
    atRuntime: (
      state,
    ): state is {
      timeOutSec: number;
      cb: AnyVoidFunction;
      nowTime: number;
    } => {
      const ret = (!!state.cb && !!state.nowTime)
      return ret;
    },
  },
  actions: {
    setTimeOut(timeSec: number, cb: AnyFunction) {
      this.timeOutSec = timeSec;
      this.cb = cb;
    },
    getNowTime() {
      return this.nowTime;
    },
    setNowTime(time: number) {
      // console.log("setNowTime", time);
      this.nowTime = time;
    },
  },
});
